<?php

/**
 * This is the model class for table "{{book}}".
 *
 * The followings are the available columns in table '{{book}}':
 * @property string $book_id
 * @property string $book_category
 * @property string $book_category_name
 * @property string $book_title
 * @property string $book_desc
 * @property string $book_author
 * @property string $book_image
 * @property string $book_url
 * @property string $book_length
 * @property string $book_vote
 * @property integer $book_status
 * @property string $book_finish_time
 */
class Book extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Book the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{book}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('book_category, book_category_name, book_title, book_desc, book_author, book_image, book_url, book_length, book_vote, book_status, book_finish_time', 'required'),
			array('book_status', 'numerical', 'integerOnly'=>true),
			array('book_category, book_length, book_vote, book_finish_time', 'length', 'max'=>10),
			array('book_category_name', 'length', 'max'=>30),
			array('book_title', 'length', 'max'=>100),
			array('book_desc', 'length', 'max'=>255),
			array('book_author', 'length', 'max'=>20),
			array('book_image, book_url', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('book_id, book_category, book_category_name, book_title, book_desc, book_author, book_image, book_url, book_length, book_vote, book_status, book_finish_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'book_id' => 'Book',
			'book_category' => 'Book Category',
			'book_category_name' => 'Book Category Name',
			'book_title' => 'Book Title',
			'book_desc' => 'Book Desc',
			'book_author' => 'Book Author',
			'book_image' => 'Book Image',
			'book_url' => 'Book Url',
			'book_length' => 'Book Length',
			'book_vote' => 'Book Vote',
			'book_status' => 'Book Status',
			'book_finish_time' => 'Book Finish Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('book_id',$this->book_id,true);
		$criteria->compare('book_category',$this->book_category,true);
		$criteria->compare('book_category_name',$this->book_category_name,true);
		$criteria->compare('book_title',$this->book_title,true);
		$criteria->compare('book_desc',$this->book_desc,true);
		$criteria->compare('book_author',$this->book_author,true);
		$criteria->compare('book_image',$this->book_image,true);
		$criteria->compare('book_url',$this->book_url,true);
		$criteria->compare('book_length',$this->book_length,true);
		$criteria->compare('book_vote',$this->book_vote,true);
		$criteria->compare('book_status',$this->book_status);
		$criteria->compare('book_finish_time',$this->book_finish_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}